Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?
Posted
by soc
on Stack Overflow
See other posts from Stack Overflow
or by soc
Published on 2010-03-19T23:25:37Z
Indexed on
2010/03/19
23:31 UTC
Read the original article
Hit count: 123
As far as I understand, Scala's == defines the natural equality of two objects.
I expected that Array(0,1,2) == Array(0,1,2)
compares the natural equality e. g. checks if all elements of the array return true when compared with the corresponding elements of the other array.
People told me that Scala's Array
is just a Java []
which only compares identity. But Scala's String
is also just a Java String
but Scala overrides equals
to compare natural equality.
I wonder why Array
's equals
method was not overridden, too.
Thank you for your thoughts!
© Stack Overflow or respective owner